<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Expires" content="0">
		<meta http-equiv="Pragma" content="no-cache">
		<meta http-equiv="Cache-control" content="no-cache">
		<meta http-equiv="Cache" content="no-cache">
		<meta charset="utf-8">
		
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		
		<title>工程保养清单</title>
	
		<link rel="stylesheet" href="../layui/css/layui.css"/>
		
	</head>
	<body>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>工程保养清单收集</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				
				<div class="layui-col-sm4">
					<label class="layui-form-label">时间类型:</label>
					<div class="layui-input-block">
						<select id="timetype" style="width:145px;">
							<option value="">请选时间类型</option>
							<option value="日">日</option>
							<option value="周">周</option>
							<option value="月">月</option>
							<option value="季">季</option>
							<option value="半年">半年</option>
							<option value="年">年</option> 
					  </select>
					</div>
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">扫描二维码:</label>
					<div class="layui-input-block">
						<input class="layui-input" placeholder="确认者或设备编号" id="qr" type="text"/>
					</div>
				</div>
				
				
				
			</div>
			
			
		</fieldset>
		
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>当前信息</b></big></legend>
			<div id="DQ" class="layui-fluid layui-form layui-form-pane">
				<div class="layui-col-sm4">
						<label class="layui-form-label">设备名称:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="设备名称" id="sheettype_name" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">设备编号:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="设备编号(机器编号)" id="JiTaiHao" type="text"/>
					</div>
				</div>
				<div class="layui-row">
					
				</div>
				<div class="layui-col-sm4">
						<label class="layui-form-label">担当者:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="担当者" id="DanDangPeople" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
						<label class="layui-form-label">确认者:</label>
						<div class="layui-input-block">
							<input class="layui-input" placeholder="确认者姓名在此处扫描" id="QueRenPeople" type="text"/>
						</div>
				</div>
				
				<!-- <label class="layui-form-label">时间类型</label> 
				<div id="ts" class="layui-input-inline">
				  <select id="timetype" style="width:145px;">
					<option value="">请选时间类型</option>
					<option value="日" selected="">日</option>
					<option value="周">周</option>
					<option value="月" selected="">月</option>
					<option value="季">季</option>
					<option value="半年">半年</option>
					<option value="年">年</option> 
				  </select>
				</div> -->
				</div>
			</div>
		</fieldset>
		
		
		<div class="container">
			<div id="my">
			
			</div>
			<div id="mytable">
			
			</div>
			
			<div align="right" class="layui-form-item">
				<div>
					<button class="layui-btn  layui-btn-radius layui-btn-normal" id="keep">存储</button>
				</div>
			</div>
		</div>
		<!-- 加载类ui文件 -->
		<link rel="stylesheet" type="text/css" href="../jexcel-master/dist/css/jquery.jexcel.css" />
		<script src="../_vendor/jquery/dist/jquery.min.js"></script>
		<script src="../jexcel-master/dist/js/jquery.jexcel.js"></script>
		<script src="../_vendor/popper.js/dist/umd/popper.min.js"></script>
		<script src="../_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="../_assets/js/custom.js"></script>
		<script src="../layui/layui.js"></script>
		<!-- 写脚本 -->
		<script>
		/**
			//这里是画面准备完毕后执行调用layui格式
		*/
			$(document).ready(function(){
				layui.use(['layer','form','element','table'], function(){
					var layer = layui.layer
						,form = layui.form
						,element = layui.element
						,table = layui.table
					;
					layer.msg('初始化正常!');
				});
				
			});
			/**
			测试表头合并单元格
			*/
			/**
			测试结束
			*/
			var qrcode="";
			var FrontTwoString="";
			var sheettype_name_id="BPA_KaoXiang";//等资料表建好后设备名称编号由设备（机台号自动带出）
			var datas=new Array();
			$("#keep").attr("disabled", false);//按钮被qi用
			/**
			获取jexcel信息
			*/
			$("#qr").keypress(function(e){
			  var key = e.which;
			  if (key == 13) {
			  qrcode=$("#qr").val();
			  timetype= (document.getElementById('timetype')).value;//工序
			  datas=[];
			 
			  $("#qr").val("");
			  FrontTwoString=(qrcode.substring(0,2));//前两位
				if(FrontTwoString=='EM'){
					$.ajax({
						type:'POST',
						async: false,
						url:"http://172.31.3.27:84/index.php?s=/scancode/shou_jian/xm",
						data:"qrc="+qrcode,
						dataType:"text",
						success:function(sss){
							$("#DanDangPeople").val(sss);
						}
					});
					if(timetype!=""&&$("#JiTaiHao").val()!=""&&$("#DanDangPeople").val()!==""){
						$.ajax({
							type:'POST',//172.31.3.27:84//127.0.0.1:85
							url: "http://127.0.0.1:85/index.php?s=/tdled/Fixmaintain/index",//POST傳一個超長字串到後端
							data:"sheettype_name_id="+sheettype_name_id+"&timetype="+timetype+"&JiTaiHao="+$("#JiTaiHao").val(),
							dataType : "json",
							success: function(sss){
							 
								console.log(sss);
								for(var k=0;k<sss['BY'].length;k++)
									{
										datas[k]=new Array(6);
										datas[k][0]=sss['BY'][k]['timetype'];
										datas[k][1]=sss['BY'][k]['BaoYangProject_name'];
										datas[k][2]=sss['BY'][k]['identify_standard'];
										datas[k][3]=sss['BY'][k]['保养情况'];
										datas[k][4]=sss['BY'][k]['担当者'];
										datas[k][5]=sss['BY'][k]['确认者'];
										if(sss['BY'][k]['担当者']==''){
											datas[k][4]=$("#DanDangPeople").val();
										}
									}
								
								console.log(datas);
								
								 $('#mytable').jexcel({ data:datas,
									// Allow column delete 
									allowDeleteColumn:false, 
									// Allow row dragging 
									rowDrag:false,
									 columns:column, 
									 colHeaders:colHeader,
									 colWidths:colWidth 
								 }); 
							}
						});	
					}
				}
				else{
					$("#DanDangPeople").val("");
					<!-- 此处暂缺设备名称编号来获取唯一保养项目 -->
					$("#JiTaiHao").val(qrcode);
					
					<!-- ------ -->
					getdatas(sheettype_name_id,timetype);
					<!-- ------- -->
				}
				
			  }
			});
			/**
			确认者姓名写入jexcel
			*/
			$("#QueRenPeople").keypress(function(e){
			  var key = e.which;
			  if (key == 13) {
				$.ajax({
					type:'POST',
					async: false,
					url:"http://172.31.3.27:84/index.php?s=/scancode/shou_jian/xm",
					data:"qrc="+$("#QueRenPeople").val(),
					dataType:"text",
					success:function(sss){
						$("#QueRenPeople").val(sss);
					}
				});
			  
				for(var i = 0;i < datas.length; i++){//循环表格中的
					datas[i][5]=$("#QueRenPeople").val();
				}
				console.log(datas);
				 $('#mytable').jexcel({ data:datas,
					// Allow column delete
					allowDeleteColumn:false, 
					// Allow row dragging 
					rowDrag:false,
					 columns:column, 
					 colHeaders:colHeader,
					 colWidths:colWidth 
				 }); 
			  }
			});
			/**
			jexcel基础搭建
			*/
		column=[
	
			{ type:'text', wordWrap:true },
			{ type:'text', wordWrap:true },
			{ type:'text', wordWrap:true },
			{ type: 'checkbox' },
			{ type:'text', wordWrap:true },
			{ type:'text', wordWrap:true },
		];		
		var colh = new Array;
		colh[0]=new Array(3);
		colh[0][0]=[
			
			'时间类型',
			'保养项目',
			'判定标准',
			'保养情况',
			'担当者',
			'确认者',
			];
		colHeader=colh[0][0];
						
		colWidth=[
			200,
			200,
			200,
			200,	
			200,
			200,				
			];
		
		$('#mytable').jexcel({ data:"", 
			 // Allow column delete 
			 allowDeleteColumn:false, 
			 // Allow row dragging 
			 rowDrag:false, 
			 columns:column, 
			 colHeaders:colHeader, 
			 colWidths:colWidth 
		 }); 
		<!-- -------------------------------------- -->
		
		$("#keep").click(function(){//保存
			$("#keep").attr("disabled", true);//按钮被禁用
			$("#keep").attr("class", 'layui-btn  layui-btn-radius layui-btn-normal layui-btn-disabled');//添加禁用渲染
					
			$.ajax({
				type:'POST',
				url: "http://127.0.0.1:85/index.php?s=/tdled/Fixmaintain/keepmaintain",//POST傳一個超長字串到後端
				data:"timetype="+timetype+"&JiTaiHao="+$("#JiTaiHao").val()+"&sheettype_name_id="+sheettype_name_id+"&ShuZu="+JSON.stringify(datas),
				dataType : "text",
				success: function(data){
					//$("#msg").val(data).css('color','green');
					layer.msg(data);
				}
			}); 
			
			
		});
		
		function getdatas(sheettype_name_id,timetype) {//获取jexcel信息
			
			$.ajax({
				type:'POST',//172.31.3.27:84//127.0.0.1:85
				url: "http://127.0.0.1:85/index.php?s=/tdled/Fixmaintain/index",//POST傳一個超長字串到後端
				data:"sheettype_name_id="+sheettype_name_id+"&timetype="+timetype+"&JiTaiHao="+$("#JiTaiHao").val(),
				dataType : "json",
				success: function(sss){
					console.log(sss);
					for(var k=0;k<sss['BY'].length;k++)
						{
							datas[k]=new Array(6);
							datas[k][0]=sss['BY'][k]['timetype'];
							datas[k][1]=sss['BY'][k]['BaoYangProject_name'];
							datas[k][2]=sss['BY'][k]['identify_standard'];
							datas[k][3]=sss['BY'][k]['保养情况'];
							datas[k][4]=sss['BY'][k]['担当者'];
							datas[k][5]=sss['BY'][k]['确认者'];
							if(sss['BY'][k]['担当者']!=''){
								$("#DanDangPeople").val(sss['BY'][k]['担当者']);
							}
							
							
						}
					
					console.log(datas);
					
					 $('#mytable').jexcel({ data:datas,
						// Allow column delete 
						allowDeleteColumn:false, 
						// Allow row dragging 
						rowDrag:false,
						 columns:column, 
						 colHeaders:colHeader,
						 colWidths:colWidth 
					 }); 
				}
			});	
		}
		
		</script>
	</body>
</html>